Change in openvpn[master]: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
A message that is not in the archive (sent off-list or not yet received): gerrit.1734706182000.I81440ac28a1ad553652e201234e5ddfe03a8c190@...2715...
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
to review the following change.
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Do not attempt to decrypt packets anymore after 2**36 failed decryptions
To avoid attacks (especially on Chacha20-Poly1305) we do not allow decryption anymore after 2**36 failed verifications.
---
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
3 files changed, 40 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/43/843/1
src/openvpn/crypto.c +10 -1
@@ -405,7 +405,13 @@ {static const char error_prefix[] ="AEAD Decrypt error" ;struct packet_id_net pin = {0 }; -const struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; +struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; + +if (cipher_decrypt_verify_fail_exceeded (ctx)) + { +CRYPT_DROP ("Decryption failed verification limit reached." ); + } +int outlen;struct gc_arena gc;
@@ -416,6 +422,8 @@ASSERT (buf->len >0 );ASSERT (ctx->cipher); + +dmsg (D_PACKET_CONTENT ,"DECRYPT FROM: %s" ,format_hex (BPTR (buf),BLEN (buf),80 , &gc));
@@ -511,6 +519,7 @@if (!cipher_ctx_final_check_tag (ctx->cipher,BPTR (&work) + outlen, &outlen, tag_ptr, tag_size)) { + ctx->failed_verifications++;CRYPT_DROP ("packet tag authentication failed" ); }ASSERT (buf_inc_len (&work, outlen));
src/openvpn/crypto.h +25 -0
@@ -181,6 +181,8 @@* with the current key in number of 128 bit blocks (only used for * AEAD ciphers) */ uint64_t plaintext_blocks; +/** number of failed verification using this cipher */ +uint64_t failed_verifications; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -623,6 +625,29 @@ cipher_get_aead_limits(const char *ciphername);/** +* Check if the number of failed decryption is over the acceptable limit. +* We +*/ +static inline bool +cipher_decrypt_verify_fail_exceeded (const struct key_ctx *ctx) +{ +/* Use 2**36, same as TLS 1.3 */ +return ctx->failed_verifications > (1ull <<36 ); +} + +/** +* Check if the number of failed decryption is approaching the limit and we +* should try to move to a new key +*/ +static inline bool +cipher_decrypt_verify_fail_warn (const struct key_ctx *ctx) +{ +/* Use 2**35, half the amount after which we refuse to decrypt */ +return ctx->failed_verifications > (1ull <<35 ); +} + + +/** * Blocksize used for the AEAD limit caluclation * * Since cipher_ctx_block_size() is not reliable and will return 1 in many
src/openvpn/ssl.c +5 -0
@@ -3042,6 +3042,11 @@return true; } +if (cipher_decrypt_verify_fail_warn (&key_ctx_bi->decrypt)) + { +return true; + } +return false; }/*
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/843?usp=email )
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Patch Set 2: Code-Review-1
(5 comments)
Patchset:
PS2:
I'm unsure if we should use the 2^36 limit for Chacha-poly, but for AES-GCM it should be ok.
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/843/comment/39d7c228_ac4d76f3 :
PS2, Line 667: We
Incomplete
http://gerrit.openvpn.net/c/openvpn/+/843/comment/e2534d46_534f661c :
PS2, Line 672: TLS 1.3
Should be DTLS
http://gerrit.openvpn.net/c/openvpn/+/843/comment/96fbdeb5_8ce34e21 :
PS2, Line 672: 2**36
I've been looking at the integrity bounds in the AEAD limits RFC again and I'm not sure if 2^36 is right for us. The number of decryption failures that we can tolerate depends on the maximum message length that we're willing to receive (L in the formulas).
The DTLS RFC assumes L <= 2^10, but for us it can be larger. I don't think this matters for AES-GCM, the 2^36 limit leaves lots of room to spare. But for Chacha-poly, it's pretty tight.
If we tolerate p = 2^-57 and we have L = 2^14, then we can only have 2^32 decryption failures.
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/843/comment/62ea554d_ed6bec9a :
PS2, Line 426:
Extra whitespace
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sat, 28 Dec 2024 00:37:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: MaxF, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/843?usp=email )
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Patch Set 2:
(1 comment)
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/843/comment/8731b0c0_7b4731b8 :
PS2, Line 672: 2**36
Quoted 1 line
I've been looking at the integrity bounds in the AEAD limits RFC again and I'm not sure if 2^36 is r […]
IP and Ethernet packets greater than 2**10 * 16 = 16k are pretty rare. Should we design for 65k packets instead?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Sat, 28 Dec 2024 01:21:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/843?usp=email )
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Patch Set 2:
(1 comment)
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/843/comment/06c9974a_c8419cbb :
PS2, Line 672: 2**36
Quoted 1 line
IP and Ethernet packets greater than 2**10 * 16 = 16k are pretty rare. […]
I don't know. I thought you did consider larger packets in the OpenVPN RFC.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sat, 28 Dec 2024 01:25:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, flichtenheld.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/843?usp=email )
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Patch Set 3:
(4 comments)
File src/openvpn/crypto.h:
http://gerrit.openvpn.net/c/openvpn/+/843/comment/6408b1af_041def26 :
PS2, Line 667: We
Quoted 1 line
Incomplete
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/843/comment/21fe7587_f0d0de4b :
PS2, Line 672: TLS 1.3
Quoted 1 line
Should be DTLS
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/843/comment/a39b0e44_3b6d137a :
PS2, Line 672: 2**36
Quoted 1 line
I don't know. I thought you did consider larger packets in the OpenVPN RFC.
I commented that we accept this since chacha with > 16k is probably super rare.
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/843/comment/33de160f_e3170849 :
PS2, Line 426:
Quoted 1 line
Extra whitespace
Acknowledged
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Sat, 04 Jan 2025 22:44:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, flichtenheld.
Hello MaxF, flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
to look at the new patch set (#4).
The following approvals got outdated and were removed:
Code-Review-1 by MaxF
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Do not attempt to decrypt packets anymore after 2**36 failed decryptions
To avoid attacks (especially on Chacha20-Poly1305) we do not allow decryption anymore after 2**36 failed verifications.
---
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
3 files changed, 41 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/43/843/4
src/openvpn/crypto.c +8 -1
@@ -405,7 +405,13 @@ {static const char error_prefix[] ="AEAD Decrypt error" ;struct packet_id_net pin = {0 }; -const struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; +struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; + +if (cipher_decrypt_verify_fail_exceeded (ctx)) + { +CRYPT_DROP ("Decryption failed verification limit reached." ); + } +int outlen;struct gc_arena gc;
@@ -511,6 +517,7 @@if (!cipher_ctx_final_check_tag (ctx->cipher,BPTR (&work) + outlen, &outlen, tag_ptr, tag_size)) { + ctx->failed_verifications++;CRYPT_DROP ("packet tag authentication failed" ); }ASSERT (buf_inc_len (&work, outlen));
src/openvpn/crypto.h +28 -0
@@ -209,6 +209,8 @@* with the current key in number of 128 bit blocks (only used for * AEAD ciphers) */ uint64_t plaintext_blocks; +/** number of failed verification using this cipher */ +uint64_t failed_verifications; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -661,6 +663,32 @@ cipher_get_aead_limits(const char *ciphername);/** +* Check if the number of failed decryption is over the acceptable limit. +*/ +static inline bool +cipher_decrypt_verify_fail_exceeded (const struct key_ctx *ctx) +{ +/* Use 2**36, same as DTLS 1.3. Strictly speaking this only guarantees +* the security margin for packets up to 2^10 blocks (16384 bytes) +* but we accept slightly lower security bound for the edge +* of Chacha20-Poly1305 and packets over 16k as MTUs over 16k are +* extremely rarely used */ +return ctx->failed_verifications > (1ull <<36 ); +} + +/** +* Check if the number of failed decryption is approaching the limit and we +* should try to move to a new key +*/ +static inline bool +cipher_decrypt_verify_fail_warn (const struct key_ctx *ctx) +{ +/* Use 2**35, half the amount after which we refuse to decrypt */ +return ctx->failed_verifications > (1ull <<35 ); +} + + +/** * Blocksize used for the AEAD limit caluclation * * Since cipher_ctx_block_size() is not reliable and will return 1 in many
src/openvpn/ssl.c +5 -0
@@ -3005,6 +3005,11 @@return true; } +if (cipher_decrypt_verify_fail_warn (&key_ctx_bi->decrypt)) + { +return true; + } +return false; }/*
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/843?usp=email )
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Patch Set 5: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 09 Jan 2025 17:14:56 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v5 1/1 Do not attempt to decrypt packets anymore after 2**36 failed decryptions
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
To avoid attacks (especially on Chacha20-Poly1305) we do not allow decryption anymore after 2**36 failed verifications.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/843
This mail reflects revision 5 of this Change.
Acked-by according to Gerrit (reflected above):
MaxF <[email protected]...>
src/openvpn/crypto.c +8 -1
@@ -405,7 +405,13 @@ {static const char error_prefix[] ="AEAD Decrypt error" ;struct packet_id_net pin = {0 }; -const struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; +struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; + +if (cipher_decrypt_verify_fail_exceeded (ctx)) + { +CRYPT_DROP ("Decryption failed verification limit reached." ); + } +int outlen;struct gc_arena gc;
@@ -511,6 +517,7 @@if (!cipher_ctx_final_check_tag (ctx->cipher,BPTR (&work) + outlen, &outlen, tag_ptr, tag_size)) { + ctx->failed_verifications++;CRYPT_DROP ("packet tag authentication failed" ); }ASSERT (buf_inc_len (&work, outlen));
src/openvpn/crypto.h +28 -0
@@ -209,6 +209,8 @@* with the current key in number of 128 bit blocks (only used for * AEAD ciphers) */ uint64_t plaintext_blocks; +/** number of failed verification using this cipher */ +uint64_t failed_verifications; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -661,6 +663,32 @@ cipher_get_aead_limits(const char *ciphername);/** +* Check if the number of failed decryption is over the acceptable limit. +*/ +static inline bool +cipher_decrypt_verify_fail_exceeded (const struct key_ctx *ctx) +{ +/* Use 2**36, same as DTLS 1.3. Strictly speaking this only guarantees +* the security margin for packets up to 2^10 blocks (16384 bytes) +* but we accept slightly lower security bound for the edge +* of Chacha20-Poly1305 and packets over 16k as MTUs over 16k are +* extremely rarely used */ +return ctx->failed_verifications > (1ull <<36 ); +} + +/** +* Check if the number of failed decryption is approaching the limit and we +* should try to move to a new key +*/ +static inline bool +cipher_decrypt_verify_fail_warn (const struct key_ctx *ctx) +{ +/* Use 2**35, half the amount after which we refuse to decrypt */ +return ctx->failed_verifications > (1ull <<35 ); +} + + +/** * Blocksize used for the AEAD limit caluclation * * Since cipher_ctx_block_size() is not reliable and will return 1 in many
src/openvpn/ssl.c +5 -0
@@ -3005,6 +3005,11 @@return true; } +if (cipher_decrypt_verify_fail_warn (&key_ctx_bi->decrypt)) + { +return true; + } +return false; }/*
[Openvpn-devel] [PATCH applied] Re: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
I have not actually tested this (hard to get 2^35 correctly-bad packets out into reasonable time...) but stared at the code, and ran the full client/server test suite "just to be sure". MaxF understands crypto and has ACKed it in Gerrit.
As discussed on IRC, I have added a few references to the commit message so people with a less deep crypto background can inform themselves what this is all about.
Your patch has been applied to the master branch.
commit ffe0ad41985d7d5f67ae6fc7d58ffa327243f76b
Author: Arne Schwabe Date: Thu Jan 9 18:49:28 2025 +0100
Do not attempt to decrypt packets anymore after 2**36 failed decryptions
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: MaxF <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30387.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#6) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/843?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by MaxF
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Do not attempt to decrypt packets anymore after 2**36 failed decryptions
To avoid attacks (especially on Chacha20-Poly1305) we do not allow decryption anymore after 2**36 failed verifications.
After 2**35, we trigger a renegotiation (to avoid that situation).
For the theoretical background, see
- https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/
- RFC 9147 (DTLS 1.3) section 4.5.3 "AEAD limits"
- https://eprint.iacr.org/2024/051.pdf
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30387.html
---
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
3 files changed, 41 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/43/843/6
src/openvpn/crypto.c +8 -1
@@ -405,7 +405,13 @@ {static const char error_prefix[] ="AEAD Decrypt error" ;struct packet_id_net pin = {0 }; -const struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; +struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; + +if (cipher_decrypt_verify_fail_exceeded (ctx)) + { +CRYPT_DROP ("Decryption failed verification limit reached." ); + } +int outlen;struct gc_arena gc;
@@ -511,6 +517,7 @@if (!cipher_ctx_final_check_tag (ctx->cipher,BPTR (&work) + outlen, &outlen, tag_ptr, tag_size)) { + ctx->failed_verifications++;CRYPT_DROP ("packet tag authentication failed" ); }ASSERT (buf_inc_len (&work, outlen));
src/openvpn/crypto.h +28 -0
@@ -209,6 +209,8 @@* with the current key in number of 128 bit blocks (only used for * AEAD ciphers) */ uint64_t plaintext_blocks; +/** number of failed verification using this cipher */ +uint64_t failed_verifications; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -661,6 +663,32 @@ cipher_get_aead_limits(const char *ciphername);/** +* Check if the number of failed decryption is over the acceptable limit. +*/ +static inline bool +cipher_decrypt_verify_fail_exceeded (const struct key_ctx *ctx) +{ +/* Use 2**36, same as DTLS 1.3. Strictly speaking this only guarantees +* the security margin for packets up to 2^10 blocks (16384 bytes) +* but we accept slightly lower security bound for the edge +* of Chacha20-Poly1305 and packets over 16k as MTUs over 16k are +* extremely rarely used */ +return ctx->failed_verifications > (1ull <<36 ); +} + +/** +* Check if the number of failed decryption is approaching the limit and we +* should try to move to a new key +*/ +static inline bool +cipher_decrypt_verify_fail_warn (const struct key_ctx *ctx) +{ +/* Use 2**35, half the amount after which we refuse to decrypt */ +return ctx->failed_verifications > (1ull <<35 ); +} + + +/** * Blocksize used for the AEAD limit caluclation * * Since cipher_ctx_block_size() is not reliable and will return 1 in many
src/openvpn/ssl.c +5 -0
@@ -3005,6 +3005,11 @@return true; } +if (cipher_decrypt_verify_fail_warn (&key_ctx_bi->decrypt)) + { +return true; + } +return false; }/*
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/843?usp=email )
Change subject: Do not attempt to decrypt packets anymore after 2**36 failed decryptions
......................................................................
Do not attempt to decrypt packets anymore after 2**36 failed decryptions
To avoid attacks (especially on Chacha20-Poly1305) we do not allow decryption anymore after 2**36 failed verifications.
After 2**35, we trigger a renegotiation (to avoid that situation).
For the theoretical background, see
- https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/
- RFC 9147 (DTLS 1.3) section 4.5.3 "AEAD limits"
- https://eprint.iacr.org/2024/051.pdf
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30387.html
---
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
3 files changed, 41 insertions(+), 1 deletion(-)
src/openvpn/crypto.c +8 -1
@@ -405,7 +405,13 @@ {static const char error_prefix[] ="AEAD Decrypt error" ;struct packet_id_net pin = {0 }; -const struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; +struct key_ctx *ctx = &opt->key_ctx_bi.decrypt; + +if (cipher_decrypt_verify_fail_exceeded (ctx)) + { +CRYPT_DROP ("Decryption failed verification limit reached." ); + } +int outlen;struct gc_arena gc;
@@ -511,6 +517,7 @@if (!cipher_ctx_final_check_tag (ctx->cipher,BPTR (&work) + outlen, &outlen, tag_ptr, tag_size)) { + ctx->failed_verifications++;CRYPT_DROP ("packet tag authentication failed" ); }ASSERT (buf_inc_len (&work, outlen));
src/openvpn/crypto.h +28 -0
@@ -209,6 +209,8 @@* with the current key in number of 128 bit blocks (only used for * AEAD ciphers) */ uint64_t plaintext_blocks; +/** number of failed verification using this cipher */ +uint64_t failed_verifications; };#define KEY_DIRECTION_BIDIRECTIONAL 0/* same keys for both directions */
@@ -661,6 +663,32 @@ cipher_get_aead_limits(const char *ciphername);/** +* Check if the number of failed decryption is over the acceptable limit. +*/ +static inline bool +cipher_decrypt_verify_fail_exceeded (const struct key_ctx *ctx) +{ +/* Use 2**36, same as DTLS 1.3. Strictly speaking this only guarantees +* the security margin for packets up to 2^10 blocks (16384 bytes) +* but we accept slightly lower security bound for the edge +* of Chacha20-Poly1305 and packets over 16k as MTUs over 16k are +* extremely rarely used */ +return ctx->failed_verifications > (1ull <<36 ); +} + +/** +* Check if the number of failed decryption is approaching the limit and we +* should try to move to a new key +*/ +static inline bool +cipher_decrypt_verify_fail_warn (const struct key_ctx *ctx) +{ +/* Use 2**35, half the amount after which we refuse to decrypt */ +return ctx->failed_verifications > (1ull <<35 ); +} + + +/** * Blocksize used for the AEAD limit caluclation * * Since cipher_ctx_block_size() is not reliable and will return 1 in many
src/openvpn/ssl.c +5 -0
@@ -3005,6 +3005,11 @@return true; } +if (cipher_decrypt_verify_fail_warn (&key_ctx_bi->decrypt)) + { +return true; + } +return false; }/*
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged